package org.dromara.Nyt7PolicyInsurance.controller;

import java.util.List;
import java.util.Map;

import lombok.RequiredArgsConstructor;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.constraints.*;
import cn.dev33.satoken.annotation.SaCheckPermission;
import org.dromara.Nyt7PolicyInsurance.domain.vo.Nyt7PolicyInsuranceCountVo;
import org.dromara.Nyt7PolicyInsurance.domain.vo.Nyt7PolicyInsuranceSearchVo;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import org.dromara.common.idempotent.annotation.RepeatSubmit;
import org.dromara.common.log.annotation.Log;
import org.dromara.common.web.core.BaseController;
import org.dromara.common.mybatis.core.page.PageQuery;
import org.dromara.common.core.domain.R;
import org.dromara.common.core.validate.AddGroup;
import org.dromara.common.core.validate.EditGroup;
import org.dromara.common.log.enums.BusinessType;
import org.dromara.common.excel.utils.ExcelUtil;
import org.dromara.Nyt7PolicyInsurance.domain.vo.Nyt7PolicyInsuranceVo;
import org.dromara.Nyt7PolicyInsurance.domain.bo.Nyt7PolicyInsuranceBo;
import org.dromara.Nyt7PolicyInsurance.service.INyt7PolicyInsuranceService;
import org.dromara.common.mybatis.core.page.TableDataInfo;

/**
 * 保单查询
 *
 * @author Lion Li
 * @date 2025-01-09
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/Nyt7PolicyInsurance/Nyt7PolicyInsurance")
public class Nyt7PolicyInsuranceController extends BaseController {

    private final INyt7PolicyInsuranceService nyt7PolicyInsuranceService;

    /**
     * 查询保单查询列表
     */
    @SaCheckPermission("Nyt7PolicyInsurance:Nyt7PolicyInsurance:list")
    @GetMapping("/list")
    public TableDataInfo<Nyt7PolicyInsuranceVo> list(Nyt7PolicyInsuranceBo bo, PageQuery pageQuery) {
        return nyt7PolicyInsuranceService.queryPageList(bo, pageQuery);
    }

    /**
     * 查询保单查询列表
     */
    @GetMapping("/all")
    public List<Nyt7PolicyInsuranceVo> all() {
        return nyt7PolicyInsuranceService.queryListAll();
    }



    /**
     * 导出保单查询列表
     */
    @SaCheckPermission("Nyt7PolicyInsurance:Nyt7PolicyInsurance:export")
    @Log(title = "保单查询", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(Nyt7PolicyInsuranceBo bo, HttpServletResponse response) {
        List<Nyt7PolicyInsuranceVo> list = nyt7PolicyInsuranceService.queryList(bo);
        ExcelUtil.exportExcel(list, "保单查询", Nyt7PolicyInsuranceVo.class, response);
    }

    /**
     * 获取保单查询详细信息
     *
     * @param id 主键
     */
    @SaCheckPermission("Nyt7PolicyInsurance:Nyt7PolicyInsurance:query")
    @GetMapping("/{id}")
    public R<Nyt7PolicyInsuranceVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable Long id) {
        return R.ok(nyt7PolicyInsuranceService.queryById(id));
    }

    /**
     * 新增保单查询
     */
    @SaCheckPermission("Nyt7PolicyInsurance:Nyt7PolicyInsurance:add")
    @Log(title = "保单查询", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody Nyt7PolicyInsuranceBo bo) {
        return toAjax(nyt7PolicyInsuranceService.insertByBo(bo));
    }

    /**
     * 修改保单查询
     */
    @SaCheckPermission("Nyt7PolicyInsurance:Nyt7PolicyInsurance:edit")
    @Log(title = "保单查询", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody Nyt7PolicyInsuranceBo bo) {
        return toAjax(nyt7PolicyInsuranceService.updateByBo(bo));
    }

    /**
     * 删除保单查询
     *
     * @param ids 主键串
     */
    @SaCheckPermission("Nyt7PolicyInsurance:Nyt7PolicyInsurance:remove")
    @Log(title = "保单查询", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] ids) {
        return toAjax(nyt7PolicyInsuranceService.deleteWithValidByIds(List.of(ids), true));
    }

    /**
     * 获取搜索建议
     */

    @GetMapping("/searchEntityFarmer")
    public R<List<Nyt7PolicyInsuranceSearchVo>> searchEntityFarmer(@RequestParam String query) {
        return R.ok(nyt7PolicyInsuranceService.searchEntityFarmer(query));
    }
    /**
     * 获取搜索建议
     */

    @GetMapping("/searchEntityPlot")
    public R<List<Nyt7PolicyInsuranceSearchVo>> searchEntityPlot(@RequestParam String query) {
        return R.ok(nyt7PolicyInsuranceService.searchEntityPlot(query));
    }


    /**
     * 获取保单数目
     */

    @GetMapping("/count")
    public R<Long> getCount() {
        Long count = nyt7PolicyInsuranceService.getCount();
        return R.ok(count);
    }

    /**
     * 获取保单数目
     */

    @GetMapping("/companyCount")
    public R<List<Nyt7PolicyInsuranceCountVo>> getCountByCompany() {
        List<Nyt7PolicyInsuranceCountVo> count = nyt7PolicyInsuranceService.getCountByCompany();
        return R.ok(count);
    }



    /**
     * 导出选中的保单查询列表
     */
    @SaCheckPermission("Nyt7PolicyInsurance:Nyt7PolicyInsurance:export")
    @Log(title = "保单查询", businessType = BusinessType.EXPORT)
    @PostMapping("/exportSelected")
    public void exportSelected(@RequestBody List<Long> ids, HttpServletResponse response) {
        List<Nyt7PolicyInsuranceVo> list = nyt7PolicyInsuranceService.queryListByIds(ids);
        ExcelUtil.exportExcel(list, "保单查询", Nyt7PolicyInsuranceVo.class, response);
    }




}
